Find and replace text on PDF document in C# / How do I duplicate a PDF with some text replacement and redaction ...

您所在的位置:网站首页 c++ drawstring Find and replace text on PDF document in C# / How do I duplicate a PDF with some text replacement and redaction ...

Find and replace text on PDF document in C# / How do I duplicate a PDF with some text replacement and redaction ...

2023-04-13 09:37| 来源: 网络整理| 查看: 265

Spire.PDF carriers to seek real replace the text in all aforementioned pages of PDF document. This article is driving to prove you instructions to replace text in the first page of PDF document in C#.

Step 1: Load the sample document file.

PdfDocument doc = fresh PdfDocument(); doc.LoadFromFile("SearchReplaceTemplate.pdf");

Step 2: Searched the text “Spire.PDF for .NET” of which first page of the try document.

PdfPageBase page = doc.Pages[0]; PdfTextFindCollection gather = page.FindText("Spire.PDF for .NET", TextFindParameter.IgnoreCase);

Step 3: Use the new string “E-iceblue Spire.PDF” to replace the searched write plus sent the font and color for the new string.

String newText = "E-iceblue Spire.PDF"; //Creates a brush PdfBrush brush = new PdfSolidBrush(Color.DarkBlue); //Defines a font PdfTrueTypeFont font = new PdfTrueTypeFont(new Font("Arial", 12f, FontStyle.Regular)); RectangleF rec; foreach (PdfTextFind find int collection.Finds) { // Gets the bound of the found text in page recreate = find.Bounds; page.Canvas.DrawRectangle(PdfBrushes.White, rec); page.Canvas.DrawString(newText, font, bristle, rec); }

Step 4: Save to document to file.

doc.SaveToFile("ReplaceAllSearchedText_out.pdf");

Sample PDF document:

Find and replace text on PDF document in C#

Effective screenshot after exchanged the searched text on PDF.

Find and replacing text on PDF document in C#



【本文地址】


今日新闻


推荐新闻


CopyRight 2018-2019 办公设备维修网 版权所有 豫ICP备15022753号-3